﻿<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title>购物车页面</title>

    <link href="../AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet"
          type="text/css"/>
    <link href="../basic/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="../css/cartstyle.css" rel="stylesheet" type="text/css"/>
    <link href="../css/optstyle.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="../js/jquery.js"></script>
    <script src="../js/jquery-2.1.0.min.js"></script>
    <script src="../HT/assets/layer/layer.js" type="text/javascript"></script>
</head>

<body>

<!--顶部导航条 -->
<div class="am-container header">
    <ul class="message-l">
        <div class="topMessage" id="userWellcome">
            <div class="menu-hd" id="user-login-label">
                <a href="./login.html" target="_top" class="h">亲，请登录</a>
                <a href="./register.html" target="_top">免费注册</a>
            </div>
        </div>
    </ul>
    <ul class="message-r">
        <div class="topMessage home">
            <div class="menu-hd">
                <a href="./home.html" target="_top" class="h">商城首页</a>
            </div>
        </div>
        <div class="topMessage my-shangcheng">
            <div class="menu-hd MyShangcheng">
                <a href="../person/index.html" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a>
            </div>
        </div>
        <div class="topMessage mini-cart">
            <div class="menu-hd">
                <a id="mc-menu-hd" href="./shopcart.html" target="_top"><i
                        class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong
                        id="J_MiniCartNum" class="h"></strong></a>
            </div>
        </div>
        <div class="topMessage favorite">
            <div class="menu-hd">
<!--                <a href="#" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a>-->
            </div>
    </ul>
</div>

<!--悬浮搜索框-->

<div class="nav white">
    <div class="logo">
        <img src="../images/logo.png"/>
    </div>
    <div class="logoBig">
        <li><img src="../images/logobig.png"/></li>
    </div>

    <div class="search-bar pr">
        <a name="index_none_header_sysc" href="#"></a>
        <form>
            <input id="searchInput" name="index_none_header_sysc" type="text"
                   placeholder="搜索" autocomplete="off"> <input
                id="ai-topsearch" class="submit am-btn" value="搜索" index="1"
                type="button">
        </form>
    </div>
</div>
<script type="text/javascript">
    //点击搜索按钮
    $("#ai-topsearch").click(function (){
        if ($("#searchInput").val().length==0){
            layer.msg('未输入关键字!', {icon: 1, time: 1000});
            return;
        }
        location.href="./search.html?key="+$("#searchInput").val();
    });
</script>

<div class="clear"></div>

<!--购物车 -->
<div class="concent">
    <div id="cartTable">
        <div class="cart-table-th">
            <div class="wp">
                <div class="th th-chk">
                    <div id="J_SelectAll1" class="select-all J_SelectAll"></div>
                </div>
                <div class="th th-item">
                    <div class="td-inner">商品信息</div>
                </div>
                <div class="th th-price">
                    <div class="td-inner">单价</div>
                </div>
                <div class="th th-amount">
                    <div class="td-inner">数量</div>
                </div>
                <div class="th th-sum">
                    <div class="td-inner">金额</div>
                </div>
                <div class="th th-op">
                    <div class="td-inner">操作</div>
                </div>
            </div>
        </div>
        <div class="clear"></div>
        <div id="carContent">
        </div>
    </div>
    <div class="clear"></div>

    <div class="float-bar-wrapper">
        <div id="J_SelectAll2" class="select-all J_SelectAll">
            <div class="cart-checkbox">
                <input class="check-all check" id="J_SelectAllCbx2"
                       name="select-all" value="true" type="checkbox"> <label
                    for="J_SelectAllCbx2"></label>
            </div>
            <span>全选</span>
        </div>
        <div class="operations">
            <a hidefocus="true" class="deleteAll">删除选中</a>
        </div>
        <div class="float-bar-right">
            <div class="amount-sum">
                <span class="txt">已选商品</span> <em id="J_SelectedItemsCount">0</em><span
                    class="txt">件</span>
                <div class="arrow-box">
                    <span class="selected-items-arrow"></span> <span class="arrow"></span>
                </div>
            </div>
            <div class="price-sum">
                <span class="txt">合计:</span> <strong class="price ">¥<em
                    id="allPrices">0</em></strong>
            </div>
            <div class="btn-area">
                <!--<a href="pay.html" id="J_Go" class="submit-btn submit-btn-disabled"
                    aria-label="请注意如果没有选择宝贝，将无法结算"> <span>结&nbsp;算</span></a>-->
                <button href="pay.html" id="submitOrder" class="submit-btn submit-btn-disabled"
                        aria-label="请注意如果没有选择宝贝，将无法结算" style="width: 80px; outline: none; border: 0px;">
                    <span>结&nbsp;算</span></button>
            </div>
        </div>

    </div>

    <div class="footer">
        <div class="footer-hd">
            <p>
                <a href="#">卓鼎教育</a> <b>|</b> <a href="#">商城首页</a> <b>|</b> <a
                    href="#">支付宝</a> <b>|</b> <a href="#">物流</a>
            </p>
        </div>
        <div class="footer-bd">
            <p style="text-align: center;">
                <a href="#">合作伙伴</a> <a href="#">联系我们</a> <a href="#">网站地图</a> <em
                    style="text-align: center;">© 2015-2025 zking 版权所有</em>
            </p>
        </div>
    </div>

</div>

<!--操作页面-->

<div class="theme-popover-mask"></div>

<div class="theme-popover" id="typeContend" style="display: none;position: fixed;">
    <div class="theme-span"></div>
    <div class="theme-poptit h-title">
        <a href="javascript:;" title="关闭" class="close">×</a>
    </div>
    <div class="theme-popbod dform">
        <form class="theme-signin" name="loginform" action="" method="post">

            <div class="theme-signin-left">

                <li class="theme-options">
                    <div class="cart-title">口味：</div>
                    <ul id="shopTypeContend">

                    </ul>
                </li>
                <div class="theme-options">
                    <div class="cart-title number">数量</div>
                    <dd>
                        <!--                        <input class="min am-btn am-btn-default" name="" type="button"-->
                        <!--                               value="-"/> <input class="text_box" name="" type="text"-->
                        <!--                                                  value="1" style="width: 30px;"/> <input-->
                        <!--                            class="add am-btn am-btn-default" name="" type="button"-->
                        <!--                            value="+"/> -->
                        <span class="tb-hidden">库存<span class="stock">1000</span>件
							</span>
                    </dd>

                </div>
                <div class="clear"></div>
                <div class="btn-op">
                </div>

            </div>
            <div class="theme-signin-right">
                <div class="img-info">
                    <img src="" class="typeImg"/>
                </div>
                <div class="text-info">
                    <span class="J_Price price-now" id="typePrice_span">¥39.00</span>
                    </span>
                </div>
            </div>

        </form>
    </div>
</div>
<!--引导 -->
<div class="navCir">
    <li><a href="home2.html"><i class="am-icon-home "></i>首页</a></li>
    <li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
    <li class="active"><a href="shopcart.html"><i
            class="am-icon-shopping-basket"></i>购物车</a></li>
    <li><a href="../person/index.html"><i class="am-icon-user"></i>我的</a></li>
</div>
<script type="text/javascript">



    //判断用户是否已经登录
    function isLogin() {
        $.ajax({
            url: "http://localhost:8080/SnacksShop/user.do?type=isLogin",
            type: "post",
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            success: function (data) {
                console.log(data);
                if (data == "101"){
                    location.href = "./login.html";
                    return;
                }

                data = JSON.parse(data); //解析为Json格式
                $("#user-login-label").hide(); //隐藏登录标签
                $("#userWellcome").html("欢迎登录&nbsp;&nbsp;<span style='color: #ff0000'>" + data.requestAPI.object.userName + "</span>");
                $("#unlogin-box-guanggao").hide();//隐藏
                $("#userImg-cebian").attr("src", data.requestAPI.object.userImg);//显示侧边用户头像
                $("#userName-cebian").text("用户名:" + data.requestAPI.object.userName);//显示侧边用户名
            },
            error: function () {

            }
        })
    }
    isLogin();
</script>
<script>
    //获取 JSON 数组长度：
    function getJsonLength(json) {
        var jsonLength = 0;
        for (var i in json) {
            jsonLength++;
        }
        return jsonLength;
    }
    $.ajax({
        url: "http://localhost:8080/SnacksShop/user.do?type=getShopCar",
        type: "post",
        crossDomain: true,
        xhrFields: {
            withCredentials: true
        },
        type: "post",
        success: function (data) {
            data = JSON.parse(data); //解析为Json格式
            temp = data;
            //temp.data.object[0][0].goods.businessName.businessName  获取店名
            var dataLength = getJsonLength(data.data.object);
            printCar(dataLength, data.data.object);

        },
        error: function (data) {

        }
    });


    function printCar(data_length, data) {
        var html = '';
        for (var i = 0; i < data_length; i++) {

            var bus_length = getJsonLength(data[i]);
            html += '<tr class="item-list"> <div class="bundle-hd"> <div class="bd-promos"> <a href="#" target="_blank" style="color: red;font-weight:bold;font-size: 25px">';
            html += data[i][0].goods.businessName.businessName + '</a></div></div>';
            html += '<div class="bundle  bundle-last "><div class="bundle-hd"><div class="bd-promos"><div class="bd-has-promo">已享优惠:<span class="bd-has-promo-content">省￥19.50</span>&nbsp;&nbsp;'
            html += '</div><div class="act-promo"><a href="#" target="_blank">第二支半价，第三支免费<span class="gt">&gt;&gt;</span></a></div><span class="list-change theme-login">编辑</span></div></div>';
            html += '<div class="clear"></div><div class="bundle-main">';
            // html += '<ul class="item-content clearfix">';
            for (var j = 0; j < bus_length; j++) {
                html += '<ul class="item-content clearfix">';
                html += '<li class="td td-chk"><div class="cart-checkbox "><input class="check oneCheck" name="' + data[i][j].carTaste.tasteId + '" type="checkbox"> </div>';
                html += '</li><li class="td td-item"><div class="item-pic"><a href="#" target="_blank" data-title="#" class="J_MakePoint" data-point="tbcart.8.12"> <img';
                html += ' src="' + data[i][j].carTaste.tasteImg + '" class="itempic J_ItemImg" width="80px" height="80px" id="img' + data[i][j].carTaste.tasteId + '" ></a>';
                html += '</div><div class="item-info"><div class="item-basic-info"><a href="#" target="_blank" title="#" class="item-title J_MakePoint" data-point="tbcart.8.11">';
                html += data[i][j].goods.goodsName + '</a><br><br><span style="color: red;float: right">';
                //判断是否降价
                if (data[i][j].goods.goodsPrice - 0 < data[i][j].carPrice - 0) {
                    html += "↓比加入时降";
                    html += (data[i][j].carPrice - data[i][j].goods.goodsPrice).toFixed(2);
                }
                html += '</span>';
                html += '</div></div></li><li class="td td-info"><div class="item-props item-props-can"><span class="sku-line" id="type-' + data[i][j].carTaste.tasteId + '"> 口味：';
                html += data[i][j].carTaste.tasteName + '</span> ';
                html += '<span tasteID="' + data[i][j].carTaste.tasteId + '" tabindex="0" ' +
                    'id="change-' + data[i][j].carTaste.tasteId + '" class="btn-edit-sku theme-login changeType" ' +
                    'typePrice="' + data[i][j].carTaste.tastePrice + '"  ' +
                    'value="' + data[i][j].goods.goodsId + '" shoptype="' + data[i][j].carTaste.tasteName + '"  ' +
                    'selectImg="' + data[i][j].carTaste.tasteImg + '" tasteNumber="' + data[i][j].carTaste.tasteNumber + '">' +
                    '修改</span> <i class="theme-login am-icon-sort-desc"></i></div></li>';
                html += '<li class="td td-price"><div class="item-price price-promo-promo"><div class="price-content">' +
                    '<div class="price-line"><em class="price-original">';
                // html += data[i][j].carTaste.tastePrice;
                html += '</em></div><div class="price-line"><em class="J_Price price-now" tabindex="0" id="oneprice' + data[i][j].carTaste.tasteId + '">';
                html += data[i][j].carTaste.tastePrice;
                html += '</em></div></div></div></li>';
                html += '<li class="td td-amount"><div class="amount-wrapper "><div class="item-amount "><div class="sl">' +
                    '<input maxNumber = "' + data[i][j].carTaste.tasteNumber + '" isChange="' + false + '" class="min am-btn" name="' + data[i][j].goods.goodsId + '" type="button" value="-"  shopID="' + data[i][j].carTaste.tasteId + '"/>' +
                    '<input maxNumber = "' + data[i][j].carTaste.tasteNumber + '" class="text_box" number="' + data[i][j].carNumber + '" price="' + data[i][j].carTaste.tastePrice + '" id="' + data[i][j].carTaste.tasteId + '" type="text" value="' + data[i][j].carNumber + '" style="width: 30px;"/> ' +
                    '<input maxNumber = "' + data[i][j].carTaste.tasteNumber + '" isChange="' + false + '" class="add am-btn" name="' + data[i][j].goods.goodsId + '" type="button" value="+" shopID="' + data[i][j].carTaste.tasteId + '"/>';
                html += '</div></div></div></li><li class="td td-sum"><div class="td-inner">  <em tabindex="0"  price ="' + data[i][j].carTaste.tastePrice + '" class="J_ItemSum number"  id="price' + data[i][j].carTaste.tasteId + '">';
                html += (data[i][j].carNumber * data[i][j].carTaste.tastePrice).toFixed(2);
                html += '</em></div></li>';
                html += ' <li class="td td-op"><div class="td-inner"><a  tasteID="' + data[i][j].carTaste.tasteId + '" id="delete-li" class="delete"> 删除</a></div></li>';
                html += '</ul>';
            }
            html += '</div></div></tr><div class="clear"></div>'

        }

        $("#carContent")[0].innerHTML = html;

        //点击结算按钮
        $("#submitOrder").click(function (){
            layer.msg('未选中商品!', {icon: 1, time: 1000});
        });
        //点击选中按钮
        $(".oneCheck").click(function () {
            changeOrder();
        })

        //点击全选按钮
        $(".check-all").click(function () {
            //勾选全部按钮
            if ($(this).is(":checked")) {
                $(".oneCheck").prop("checked", true);
            } else {
                $(".oneCheck").prop("checked", false);
            }
            changeOrder();
        })

        //点击删除选中按钮
        $(".deleteAll").click(function () {
            var myArray = new Array();
            var count = 0;
            //判断是否选中
            for (var i = 0; i < $(".oneCheck").length; i++) {
                var temp = $(".oneCheck")[i];
                if ($(temp).is(":checked")) {
                    myArray[count] = $(temp).attr("name");
                    count++;
                }
            }
            if (count == 0) {
                layer.msg('未选中商品!', {icon: 1, time: 1500});
                return;
            }

            var temp = false;
            //判断是否删除全部
            if ($(".oneCheck").length == myArray.length) {
                temp = true;
            }
            layer.confirm('选中的商品会被删除？', {icon: 0,}, function () {
                console.log(myArray);
                $.ajax({
                    url: "http://localhost:8080/SnacksShop/user.do?type=deleteSomeCar",
                    type: "post",
                    data: {
                        myArray: JSON.stringify(myArray),
                        isAll: temp
                    },
                    crossDomain: true,
                    xhrFields: {
                        withCredentials: true
                    },
                    type: "post",
                    success: function (data) {
                        if (data == "true") {
                            for (var j = 0; j < count; j++) {
                                var index = "#" + myArray[j];
                                //如果该店铺只存在一个商品时
                                if ($(index).parents("ul").prev().length == 0 && $(index).parents("ul").next().length == 0) {
                                    $(index).parents(".bundle-last").prev().remove();//删除该列
                                    $(index).parents(".bundle-last").remove();//删除该店铺
                                }
                                $(index).parents("ul").remove();//删除该列商品
                                layer.msg('已删除!', {icon: 1, time: 1000});
                            }
                            changeOrder();
                        } else {
                            layer.msg('网络出错!', {icon: 1, time: 1000});
                        }
                    },
                    error: function (data) {
                        layer.msg('网络出错!', {icon: 1, time: 1000});
                    }
                });
            });

        })

        //修改结算金额
        function changeOrder() {
            var myArray = new Array();
            var count = 0;
            //判断是否选中
            for (var i = 0; i < $(".oneCheck").length; i++) {
                var temp = $(".oneCheck")[i];
                if ($(temp).is(":checked")) {
                    myArray[count] = $(temp).attr("name");
                    count++;
                }
            }
            var allPrice = 0;
            for (var j = 0; j < myArray.length; j++) {
                allPrice += (document.getElementById("price" + myArray[j]).innerHTML - 0);
            }
            document.getElementById("allPrices").innerText = allPrice.toFixed(2);
            $("#J_SelectedItemsCount").text(myArray.length);
            //修改全选框
            if (myArray.length == $(".oneCheck").length & myArray.length != 0)
                $(".check-all").prop("checked", true);
            else
                $(".check-all").prop("checked", false);

            console.log(myArray);
            //修改结算按钮颜色
            if (myArray.length > 0){
                $("#submitOrder").css("color", "red");
                $("#submitOrder").click(function (){
                    layer.msg("选中", {icon: 1, time: 1000});
                    var tasteIDs = "";
                    for (var i = 0; i < myArray.length; i++) {
                        tasteIDs+=myArray[i]+"_";
                    }
                    location.href="./pay.html?tasteIDs="+tasteIDs;
                });
            }
            else {
                $("#submitOrder").css("color", "#fff");
            }
        }

        //点击修改按钮
        $(".changeType").click(function () {
            $(".typeImg").attr("src", this.getAttribute("selectImg"));
            $("#typePrice_span").text("￥" + this.getAttribute("typePrice"));
            $(".stock").text(this.getAttribute("tasteNumber"));
            //获取商品ID
            var shopID = this.getAttribute("value");
            var tasteID = this.getAttribute("tasteID")
            var shoptype = this.getAttribute("shoptype");
            $.ajax({
                url: "http://localhost:8080/SnacksShop/user.do?type=queryGoodTypeByID",
                type: "post",
                data: {
                    shopID: shopID
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success: function (data2) {
                    data2 = JSON.parse(data2);
                    printType(data2.data.object.length, data2.data.object, shoptype, tasteID)
                },
                error: function (data2) {

                }
            });
            $("#typeContend").css("display", "block");

        });

        //点击减号
        $(".min").click(function () {
            var shopID = this.getAttribute("shopID");  //口味ID
            if (document.getElementById(shopID).value == 1) {
                var index = $(this);
                layer.confirm('该商品会被删除？', {icon: 0,}, function () {
                    //如果该店铺只存在一个商品时
                    if ($(index).parents("ul").prev().length == 0 && $(index).parents("ul").next().length == 0) {
                        $(index).parents(".bundle-last").prev().remove();//删除该列
                        $(index).parents(".bundle-last").remove();//删除该店铺
                    }
                    $(index).parents("ul").remove();//删除该列商品
                    layer.msg('已删除!', {icon: 1, time: 1000});
                    deleteOneCar(shopID);
                }, function () {
                    console.log("取消");
                });
            } else {
                $(this).attr("isChange", "true");
                document.getElementById(shopID).value = document.getElementById(shopID).value - 1;
                document.getElementById("price" + shopID).innerText = (document.getElementById("price" + shopID).getAttribute("price") * document.getElementById(shopID).value).toFixed(2);
            }
            changeOrder();
        });
        //点击加号
        $(".add").click(function () {
            var shopID = this.getAttribute("shopID");
            if ((this.getAttribute("maxNumber") - 0) < (document.getElementById(shopID).value - 0 + 1)) {
                layer.msg('已超库存!', {icon: 1, time: 1000});
                return
            }
            document.getElementById(shopID).value = document.getElementById(shopID).value - 0 + 1;
            document.getElementById("price" + shopID).innerText = (document.getElementById("price" + shopID).getAttribute("price") * document.getElementById(shopID).value).toFixed(2);
            $(this).attr("isChange", "true");
            changeOrder();
        });

        //当鼠标离开+执行数据库更新操作
        $(".add").mouseleave(function () {
            if ($(this).attr("isChange") == "false")
                return
            var tasteID = $(this).attr("shopID");
            changeNumber(tasteID);
            $(this).attr("isChange", "false");
        });
        //当鼠标离开-号按钮时更新数据库
        $(".min").mouseleave(function () {
            if ($(this).attr("isChange") == "false")
                return
            var tasteID = $(this).attr("shopID");
            changeNumber(tasteID);
            $(this).attr("isChange", "false");
        });

        //点击删除按钮
        $(".delete").click(function () {
            var index = $(this);
            layer.confirm('该商品会被删除？', {icon: 0,}, function () {
                //如果该店铺只存在一个商品时
                if ($(index).parents("ul").prev().length == 0 && $(index).parents("ul").next().length == 0) {
                    $(index).parents(".bundle-last").prev().remove();//删除该列
                    $(index).parents(".bundle-last").remove();//删除该店铺
                }
                $(index).parents("ul").remove();//删除该列商品
                layer.msg('已删除!', {icon: 1, time: 1000});
                deleteOneCar($(index).attr("tasteID"));
                changeOrder();
            });

        })

        //修改购物车数据
        function changeNumber(tasteID) {
            var number = document.getElementById(tasteID).value;
            $.ajax({
                url: "http://localhost:8080/SnacksShop/user.do?type=changeCarNumber",
                type: "post",
                data: {
                    tasteID: tasteID,
                    number: number
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success: function (data) {
                },
                error: function (data) {
                }
            });
        }

        //删除单条记录
        function deleteOneCar(tasteID) {
            $.ajax({
                url: "http://localhost:8080/SnacksShop/user.do?type=deleteOneCar",
                type: "post",
                data: {
                    //口味ID
                    tasteID: tasteID,
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success: function (data) {
                    if (data == "200") {
                        layer.msg('删除成功!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('删除失败!', {icon: 1, time: 1000});
                    }
                },
                error: function (data) {
                    layer.msg('网络问题!', {icon: 1, time: 1000});
                }
            });
        }

        // //修改购物车中的口味
        // function changeTasteID(firstTasteID, secondTasteID) {
        //     console.log(firstTasteID + secondTasteID)
        //     // $.ajax({
        //     //     url: "http://localhost:8080/SnacksShop/user.do?type=deleteOneCar",
        //     //     type: "post",
        //     //     data: {
        //     //         //口味ID
        //     //         tasteID: tasteID,
        //     //     },
        //     //     crossDomain: true,
        //     //     xhrFields: {
        //     //         withCredentials: true
        //     //     },
        //     //     type: "post",
        //     //     success: function (data) {
        //     //         if (data == "200") {
        //     //             layer.msg('删除成功!', {icon: 1, time: 1000});
        //     //         } else {
        //     //             layer.msg('删除失败!', {icon: 1, time: 1000});
        //     //         }
        //     //     },
        //     //     error: function (data) {
        //     //         layer.msg('网络问题!', {icon: 1, time: 1000});
        //     //     }
        //     // });
        // }

        //当商品数量框发生改变时
        $(".text_box").change(function () {
            //记录原先的数量当输入不合法时重置
            var numberTemp = $(this).attr("number");
            if (!(/(^[1-9]\d*$)/.test($(this).val()))) {
                layer.msg('数据必须为大于0的整数!', {icon: 1, time: 1000});
                $(this).val(numberTemp);
                return;
            }
            //判断是否超库存
            if (($(this).attr("maxNumber") - 0) < ($(this).val() - 0)) {
                layer.msg('已超库存!', {icon: 1, time: 1000});
                $(this).val(numberTemp);
                return
            }
            $(this).attr("number", $(this).val());
            //修改总价
            document.getElementById("price" + this.getAttribute("id")).innerText = ($(this).val() * this.getAttribute("price")).toFixed(2);
            changeNumber(this.getAttribute("id"));
            changeOrder();
        })
    }

    //打印口味
    function printType(data_length, data, shoptype, tasteID) {
        var html = '';
        for (var i = 0; i < data_length; i++) {
            if (data[i].tasteName == shoptype) {
                html += '<li typeName="' + data[i].tasteName + '" goodsID="' + data[i].goods.goodsId + '"  typeID="' + data[i].tasteId + '"' +
                    'class="sku-line selected" tasteNumber="' + data[i].tasteNumber + '" imgsrc="' + data[i].tasteImg + '" typePrice="' + data[i].tastePrice + '">' + data[i].tasteName + '<i></i></li>';
            } else {
                html += '<li typeName="' + data[i].tasteName + '" goodsID="' + data[i].goods.goodsId + '"  typeID="' + data[i].tasteId + '" ' +
                    'class="sku-line" tasteNumber="' + data[i].tasteNumber + '" imgsrc="' + data[i].tasteImg + '" typePrice="' + data[i].tastePrice + '">' + data[i].tasteName + '<i></i></li>';
            }
        }
        var html2 = '<div class="btn am-btn am-btn-warning refre">确认</div>' +
            '<div class="btn close am-btn am-btn-warning typeclose">取消</div>';
        $(".btn-op").html(html2);
        $("#shopTypeContend").html(html);


        var firstTasteID, secondTasteID;
        //点击确定按钮
        //选中口味
        $(".sku-line").click(function () {
            firstTasteID = $(".selected").attr("typeID");
            $(".sku-line").removeClass("selected");
            $(this).addClass("selected");
            $(".typeImg").attr("src", $(".selected").attr("imgsrc"));  //修改图片
            $("#typePrice_span").text("￥" + $(".selected").attr("typePrice"));//修改价格
            $(".stock").text($(".selected").attr("tasteNumber"));//修改库存
            secondTasteID = $(".selected").attr("typeID");
        });


        //点击确定按钮
        $(".refre").click(function () {
            var selected = $(".selected");
            $("#shopTypeContend").html("");
            if (data_length == 1) {
                $("#typeContend").css("display", "none");
                return;
            }
            //修改数据库
            $.ajax({
                url: "http://localhost:8080/SnacksShop/user.do?type=changeCarType",
                type: "post",
                data: {
                    //口味ID
                    firstTasteID: firstTasteID,
                    secondTasteID: secondTasteID
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success: function (data) {
                    if (data == "repetition") {
                        layer.msg('该口味已经存在购物车中无法修改!', {icon: 1, time: 2000});
                        return
                    }
                    //获取价格
                    var price = selected.attr("typePrice");
                    //获取图片
                    var typeImg = selected.attr("imgsrc");
                    console.log(typeImg);
                    //获取商品ID
                    var goodsID = selected.attr("goodsID");
                    //获取口味ID
                    var taste = selected.attr("typeID");
                    //修改修改按钮的属性
                    document.getElementById("change-" + tasteID).setAttribute("typeID", taste);
                    //修改购物车中的图片
                    document.getElementById("img" + tasteID).setAttribute("src", typeImg);
                    //修改购物车中该商品的价格
                    document.getElementById("oneprice" + tasteID).innerText = price - 0;
                    document.getElementById("price" + tasteID).setAttribute("price", price);
                    //修改总价格
                    document.getElementById("price" + tasteID).innerText = ($(".text_box").val() * price).toFixed(2);
                    //修改口味标签
                    document.getElementById("change-" + tasteID).setAttribute("shoptype", selected.attr("typeName"))
                    document.getElementById("change-" + tasteID).setAttribute("selectImg", typeImg);
                    document.getElementById("type-" + tasteID).innerText = "口味:" + selected.attr("typeName");
                },
                error: function (data) {
                    layer.msg('网络问题!', {icon: 1, time: 1000});
                }
            });
            //关闭
            $("#typeContend").css("display", "none");

        });

        //点击取消按钮
        $(".typeclose").click(function () {
            // $("#shopTypeContend").html("");
            $("#typeContend").css("display", "none");
        })
    }

</script>
</body>

</html>